home *** CD-ROM | disk | FTP | other *** search
- /*******************************************************************************
- +
- + LEDA 2.1.1 11-15-1991
- +
- +
- + b_queue.h
- +
- +
- + Copyright (c) 1991 by Max-Planck-Institut fuer Informatik
- + Im Stadtwald, 6600 Saarbruecken, FRG
- + All rights reserved.
- +
- *******************************************************************************/
-
-
-
-
-
- #ifndef BQUEUEH
- #define BQUEUEH
-
- //------------------------------------------------------------------------------
- // bounded queues
- //
- // Stefan Naeher (1989)
- //------------------------------------------------------------------------------
-
- #include <LEDA/basic.h>
-
-
- #define b_queue(type) name2(type,b_queue)
-
- #define b_queuedeclare(type)\
- class b_queue(type){\
- type* v;\
- int n;\
- int start;\
- int end;\
- public: \
- b_queue(type)(int s) \
- { if (s<1) error_handler(88,"b_queue: bad size");\
- n = s+1; \
- v = new type[n];\
- if (v==0) error_handler(88,"b_queue: out of memory");\
- start = end = 0; \
- }\
- \
- ~b_queue(type)() {}\
- \
- int empty() const { return (size()==0) ? true : false; }\
- \
- int size() const \
- { int s = end-start;\
- return (s<0) ? (n+s) : s;\
- }\
- \
- void append(type& a)\
- { v[end++] = a;\
- end %= n;\
- if (start==end) error_handler(88, "b_queue overflow");\
- }\
- \
- type pop()\
- { if (start==end) error_handler(88, "b_queue underflow");\
- type x = v[start];\
- start = (start+1) % n;\
- return x;\
- }\
- \
- type top() const\
- { if (start==end) error_handler(88, "b_queue empty");\
- return v[start];\
- }\
- \
- void clear() { start = end = 0; }\
- };
-
-
- #endif
-